import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';

import 'package:get/get.dart';
import 'package:smart_translator/app/event/DataCallBack.dart';
import '../../../style/widget_style.dart';
import '../../../utils/CommonUtil.dart';
import '../../../views/controller/RecordTranscriptViewRecordingController.dart';
import '../../../widgets/AppHeader.dart';
import '../controllers/edit_scriptlist_controller.dart';

class EditScriptlistView extends GetView<EditScriptlistController> {

  const EditScriptlistView({super.key});

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        top: false,
        child: Scaffold(
            body: Stack(
              children: [
                Container(
                  child: SvgPicture.asset(
                    "assets/images/header_part_bg.svg",
                    width: Get.width,
                  ),
                ),
                Obx(()=> controller.hasTranScript.value ? Container(
                  width: Get.width,
                  height: Get.height,
                  margin: EdgeInsets.only(top: 55.h),
                  child: Container(
                    margin: EdgeInsets.all(18.w),
                    child: ListView.builder(itemBuilder: (context, index) {
                      AudioTranscriptDataExtends audio = controller.audioTranscriptSource.value[index];
                      if (audio != null) {
                        return Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Container(
                              padding: EdgeInsets.all(18.w),
                              decoration: BoxDecoration(
                                  shape: BoxShape.rectangle,
                                  borderRadius: BorderRadius.all(Radius.circular(20)),
                                  color: Colors.white
                              ),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
                                    Row(
                                      children: [
                                        Text('${CommonUtil.getMMSSFormate(audio.duration)}',style: AppStyleThemeData.HINT_TEXT_STYLE_small),
                                        SizedBox(width: 23.w,),
                                        Icon(Icons.person,color: Colors.grey,),
                                        Text('${audio.speaker}',style: AppStyleThemeData.HINT_TEXT_STYLE_small,)
                                      ],
                                    ),
                                  ],
                                  ),
                                  SizedBox(height: 10.w,),
                                  Container(
                                    width: Get.width,
                                    child: TextField(
                                      controller: audio.textEditingController,
                                      maxLines: null,
                                      decoration: InputDecoration(
                                        contentPadding: EdgeInsets.all(5), // 完全去掉内边距
                                        focusedBorder: OutlineInputBorder(
                                          borderSide: BorderSide(color: Colors.blue, width: 1.0),
                                          borderRadius: BorderRadius.circular(8.0),
                                        ),
                                      ),
                                      onChanged: (v) {
                                        controller.saveBatches();
                                      },
                                    ),

                                  )
                                ],
                              ),
                            ),
                            SizedBox(height: 16.h,),

                          ],
                        );
                      }

                    },
                    itemCount: controller.audioTranscriptSource.length,
                   ),
                 ),
               ): Center(
                  child: Column(
                    children: [
                      SizedBox(height: 80.h,),
                      Image.asset('assets/images/empty_list_realtime.png',width: 169.w,height: 91.h),
                      SizedBox(height: 16.h,),
                      Text('暂无转写记录',style: AppStyleThemeData.HINT_TEXT_STYLE_small,)
                    ],
                  ),
                )),
                Positioned(
                    top: 0,
                    child: AppHeader.obtainHeaderForEditorScript())
            ],
          )
        ));;
  }
}
